HAL ADC migration: List of applicable concepts

This section provides information about the applicable HAL ADC architecture concepts.

Concepts for ADC

Concept

Description

Separation of initialization and configuration functions

The init and config have been split into three functions:

  • HAL_ADC_Init: initializes the handle and links it to an ADC instance.

  • HAL_ADC_SetConfig: configures the common ADC settings (resolution and sampling).

  • HAL_ADC_REG_SetConfig/ HAL_ADC_INJ_SetConfig: allow the configuration of the ADC for regular or injected conversion.

Removal and conversion of init structure to configuration structure

The init structure has been removed and moved to the HAL_ADC_SetConfig function.

Renaming of the handle structure

The handle structure has been renamed hal_adc_handle_t.

Renaming unitary init structures

The structure ADC_InitTypeDef is no longer available and has been replaced by hal_adc_config_t, hal_adc_post_processing_config_t, and hal_adc_low_power_config_t.

Remove MspInit and MspDeInit callbacks

hal_adc_MspInit and hal_adc_MspDeInit are no longer available and have been replaced by a user sequence to initialize and configure the ADC.

Unitary configuration APIs

New APIs are available to get and set ADC features.

Dedicated DMA link APIs replace generic __HAL_LINKDMA macro

The __HAL_LINKDMA macro is no longer provided and new functions HAL_ADC_REG_SetDMA is provided to link an ADC HAL handle to a DMA HAL handle.

Introduction of HAL user data set/get APIs

Two functions to set and get user data are available: HAL_ADC_SetUserData and HAL_ADC_GetUserData.

Individual callback registration APIs replace global register and unregister functions

The callback registration is handled by specific functions for each ADC event. These functions are used to register callback functions for different ADC events.

Introduce specialized IRQ handlers

HAL_ADC_IRQHandler is still available, and three new IRQ handlers were added:

  1. HAL_ADC_IRQHandler_REG() specific to ADC regular group

  2. HAL_ADC_IRQHandler_INJ() specific to ADC injected group

  3. HAL_ADC_IRQHandler_AWD() specific to ADC analog watchdog

HAL implementation with LL inline functions

HAL ADC APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL ADC define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL ADC driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL state machine

The ADC now is managed by three state machines:

  1. Global state machine

  2. Group state machine

  3. Common state machine

Revised and optimized HAL API status returns

The HAL ADC functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_TIMEOUT: in case of a user timeout.

  • HAL_BUSY: in case of an ongoing process.

  • HAL_OK: in case of a successfully completed operation.

Revised and optimized HAL error management

The HAL error handling mechanisms have been redesigned to improve the detection, reporting, and handling of errors. This provides more detailed and consistent error information, like HAL_ADC_ERROR_INTERNAL and HAL_ADC_REG_ERROR_DMA.

New APIs for filtering optional asynchronous process interrupts

New ADC functions filter and manage asynchronous process interrupts, such as HAL_ADC_SetConfigPostProcessing.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL ADC driver have been removed and replaced by _t.

Replaced multi-line macros with inline functions

For the HAL ADC driver, large macros have been replaced by inline functions to maintain code consistency, improve readability, and benefit from compiler optimization. Inline functions also offer better support for debugging and strict type management, reducing the risk of errors.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

The ASSERT_DBG_STATE and ASSERT_DBG_PARAM macros are used to check the parameters and state of the HAL ADC driver.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL ADC header file remains and all macros, define statements, and functions from hal_adc_ex.h have been moved to hal_adc.h.

Add HAL PPP Services for Drivers with Handle to Retrieve Corresponding Peripheral Clock Frequency.

The HAL ADC driver provides a new function to retrieve the clock frequency: HAL_ADC_GetClockFreq.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including ADC instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Other HAL ADC changes

Concept

Consideration

The HAL_ADC_Start/Stop() function have been reworked.

The HAL_ADC_Start() and HAL_ADC_Stop() functions have both been split into two distinct functions:

  1. HAL_ADC_Start() split into :
    1. HAL_ADC_Start()

    2. HAL_ADC_REG_StartConv() / _XXX()

  2. HAL_ADC_Stop() split into :
    1. HAL_ADC_Stop()

    2. HAL_ADC_REG_StopConv() / _XXX()